1. /* slostrm.cpp by K.Tsuru */
  2. // function ID = 263 DARDIX
  3. /***************
  4. SLong class
  5. output stream since version 2.30
  6. ****************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. /*
  11. It returns n-th digit by a character. n = 0 for first position
  12. For continuously picking out a static array buff[] is used.
  13. int SLong::CharNthFig(long n) const;
  14. in "slmput.cpp".
  15. */
  16. /*
  17. main body
  18. */
  19. long SLong::figUnit = 10;
  20. int SLong::perLine = 0;
  21. int SLong::lineFormat = SLong::CRLF;
  22. int SLong::delmt = ' ';
  23. long SLong::ioCount = 0; // the number of input or output characters
  24. // static void SetFormat(long fU, long pL = 0, int lF = CRLF, int dm = ' '); in slong.h
  25. // enum { NO_CR = 0, CRLF = 1, CONTINUE = 2, END_CR =4 };
  26. void SLong::SetFormat(long fU, long pL, int lF, int dm){
  27. figUnit = fU; perLine = pL; lineFormat = lF; delmt = dm;
  28. }
  29. void SLong::DefaultFormat(){ // It restores the default values.
  30. figUnit = 10; perLine = 0; lineFormat = CRLF; delmt = ' ';
  31. }
  32. ostream& operator<<(ostream& os, const SLong& sl)
  33. {
  34. // sl.SignCheck(204); // sign == UNDECIDED ?
  35. SLong temp(sl);
  36. sl.ioCount = 0;
  37. if(!sl.figUnit){ sl.figUnit = LONG_MAX; sl.delmt = 0; }
  38. long f = temp.DFigures();
  39. long numCount = f; //counter for output digits
  40. int uCount = 0; //counter for 'fig' figures
  41. long lunit = sl.perLine ? sl.perLine : (displayWidth+1)/(sl.figUnit+1);//units per line
  42. if(temp.Sign(204) == 0){ os.put('0'); sl.ioCount++; goto Ret; }
  43. if(!lunit) lunit = 1;
  44. //output negative sign
  45. if( temp.Sign(204) == -1 ) { os.put('-'); sl.ioCount++; }
  46. //integral part
  47. temp.CharNthFig(-1L);
  48. while(1){
  49. os.put( temp.CharNthFig(numCount -1) ); sl.ioCount++;
  50. numCount--;
  51. if(!numCount) break;
  52. if( !(numCount % sl.figUnit) ) { //output one unit
  53. uCount++;
  54. if(!(uCount % lunit)){ //reach the end of line
  55. if(sl.delmt != ' ') {
  56. os.put(sl.delmt); sl.ioCount++;
  57. }
  58. if(sl.lineFormat & sl.CONTINUE){ os.put('\\'); sl.ioCount++; }
  59. if(sl.lineFormat & sl.CRLF) { os << endl; sl.ioCount++; }
  60. if(sl.lineFormat == sl.NO_CR) { os.put(sl.delmt); sl.ioCount++; }
  61. } else {
  62. os.put(sl.delmt); sl.ioCount++;
  63. }
  64. }
  65. }
  66. Ret:
  67. if(sl.lineFormat & sl.END_CR){ os << endl; sl.ioCount++; }
  68. return os;
  69. }

slostrm.cpp : last modifiled at 2017/07/17 15:28:16(2,268 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).